xlv.obj.textarea={
	extend:function(){
	},
	implement:function(){
		this.implement('xlv.imp.mvc');
		this.implement('xlv.imp.editor');		
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.textarea');
		return div;			
	},
	properties:{
		dmName:null,
		dmPath:null,
		cols:null,
		rows:null,
		width:null,
		height:null
	},
	method:{
		construct:function(){
			var v=this.$V;
			v.textarea=xlv.util.isTag(this,'textarea') ? this :xlv.util.findChild(this,{tag:'textarea'});
			if(!v.textarea){
				v.textarea=document.createElement('textarea');
				if(this.$P.cols)v.textarea.setAttribute('cols',this.$P.cols);
				if(this.$P.rows)v.textarea.setAttribute('rows',this.$P.rows);
				if(this.$P.width)v.textarea.setAttribute('width',this.$P.width);
				if(this.$P.height)v.textarea.setAttribute('height',this.$P.height);
				this.appendChild(v.textarea);
			}
			this.styleFor(v.textarea);
		},
		initial:function(){
			this.addEventHandler('blur','_blur',this.$V.textarea);
			this.addEventHandler('focus','_focus',this.$V.textarea);
		},
		styleFor:function(textarea){
		},
		dispose:function(){
		},
		_blur:function(event){
			if(this.editor_editing())this._editor_endEdit(true);
		},
		_focus:function(event){
			if(!this.editor_editing())this._editor_startEdit();
		},
		/**mvc imp*/
		mvc_valueFromModel:function(dm){
			return this.mvc_isModel(dm) ? dm.getValue(this.$P.dmPath) : null;
		},
		mvc_valueToModel:function(value,dm){
			if(this.mvc_isModel(dm)) dm.setValue(value,this.$P.dmPath);
		},
		mvc_beforeModelChanged:function(model,notify,memo){
			if(this.mvc_isModel(model)&& notify=='cursorMove'&& this.editor_editing())
				this._editor_endEdit(true);
		},
		mvc_valueFromView:function(){
			return this.editor_valueFromEditor();
		},
		mvc_valueToView:function(value){
			this.editor_valueToEditor(value);
		},
		/**editor imp*/
		editor_startEdit:function(){
			Element.removeClassName(this.$V.textarea,'validate_error');
		},
		editor_valueToEditor:function(value){
			this.$V.textarea.value=value;
		},
		editor_valueFromEditor:function(){
			return this.$V.textarea.value;
		},
		editor_endEdit:function(commit){
			var dm=this.mvc_getModel();
			if(dm && commit)this.mvc_valueToModel(this.editor_valueFromEditor(),dm);
			if(dm && !commit)this.editor_valueToEditor(this.mvc_valueFromModel(dm));
		},
		editor_validate:function(){
			var valid=(this.$P.validateRegExp)?this.$P.validateRegExp.match(this.editor_valueFromEditor()):true;
			if(valid) Element.removeClassName(this.$V.textarea,'validate_error');
			else Element.addClassName(this.$V.textarea,'validate_error');
			return valid;
		}
	}
};
